package nullby.yoga.adapter;

import java.util.List;

import nullby.yoga.R;
import nullby.yoga.bo.Programm;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ProgrammAdapter extends ArrayAdapter<Programm> {
	private List<Programm> objects;
	private LayoutInflater inflater;

	public ProgrammAdapter(Context context, int textViewResourceId,
			List<Programm> objects) {
		super(context, textViewResourceId, objects);
		this.objects = objects;
		inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public View getView(int position, View vi, ViewGroup parent) {
		if (vi == null) {
			vi = inflater.inflate(R.layout.program_item, null);
		}
		Programm programm = objects.get(position);
		ImageView iv = (ImageView) vi.findViewById(R.id.ivProgrammIconItem);
		iv.setImageResource(getContext().getResources().getIdentifier(
				programm.getIcon(), "drawable", getContext().getPackageName()));
		iv.setPadding(0, 5, 20, 5);
		TextView t = (TextView) vi.findViewById(R.id.tvProgrammNameItem);
		t.setText(programm.getName());

		return vi;
	}

}
